package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.OrderBean;
import com.project.bean.ProductBean;
import com.project.bean.ShopBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface IOrderMapper extends BaseMapper<OrderBean> {
    /**
     * 添加订单明细
     * @param orderId 订单ID
     *
     * @param shopList 购物车集合
     */
    public void   addOrderInfo(@Param("orderId") int orderId, @Param("shopList") List<ShopBean>shopList);

    /**
     * 查询所有“发货中”的订单
     * @return
     */
    @Select("SELECT *FROM t_order WHERE o_status='发货中'")
    @ResultMap("oMap")
    public List<OrderBean>findBySend();

    /**
     * 管理员权限 动态查询所有订单
     * @param status 订单状态
     * @param startDate 起始日期
     * @param endDate 结束日期
     * @return 分页对象
     */
    public  IPage<OrderBean>findByItem(Page<OrderBean> page, @Param("status") String status, @Param("startDate")LocalDate startDate, @Param("endDate")LocalDate endDate);


    /**
     * 根据订单ID查询该订单的明细，在订单明细中需要查询购买商品编号，商品名 单价
     * @param orderId 订单ID
     * @return 订单对象
     */
    @Select("SELECT o.*,p.pk_productId,p.p_name,p.p_price,oi.oi_num FROM t_order o,t_orderInfo oi,t_product\n" +
            " p WHERE oi.fk_productId=p.pk_productId AND\n" +
            " oi.fk_orderId=o.pk_orderId AND o.pk_orderId=#{orderId}")
    @ResultMap("oMap")
    public  OrderBean findById(int orderId);




}
